package com.njupt.controller;

import com.njupt.common.pojo.EasyUITreeNode;
import com.njupt.common.pojo.TaotaoResult;
import com.njupt.content.service.ItemContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: XJL
 * @Description:
 * @Date: Create in 15:58 2018/5/28
 * @Modified By:
 **/
@Controller
public class ContentCategoryController {

    @Autowired
    private ItemContentCategoryService itemContentCategoryService;

    /**
     * 内容分类列表
     * @param parentId
     * @return
     */
    @ResponseBody
    @RequestMapping("/content/category/list")
    public List<EasyUITreeNode> getContentCategory(@RequestParam(value = "id", defaultValue = "0") Long parentId){
        List<EasyUITreeNode> list = itemContentCategoryService.getItemCategoryList(parentId);
        return list;
    }

    /**
     * 内容分类添加
     * @param parentId
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping("/content/category/create")
    public TaotaoResult addContentCategory(@RequestParam("parentId") Long parentId,@RequestParam("name") String name){

       TaotaoResult result = itemContentCategoryService.addContentCategory(parentId,name);
        return result;
    }

    /**
     * 内容分类重命名
     * @param id
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping("/content/category/update")
    public TaotaoResult updateContentCategory(Long id,String name){
        TaotaoResult result = itemContentCategoryService.updateContentCategory(id,name);
        return result;
    }

    /**
     * 内容分类删除
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/content/category/delete/")
    public TaotaoResult deleteContentCategory(Long id){
        //System.out.println("parentId="+parentId+","+"id="+id);
        TaotaoResult result = itemContentCategoryService.deleteContentCategory(id);
        return result;
    }
}
